C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
bank.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2021 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_BANK_H
17#define SIMICS_BANK_H
18
19#include <string_view>
20#include <optional>
21#include <map>
22#include <string>
23#include <vector>
24#include <utility>
25#include <memory>
26
27#include "hierarchical-object.h"
28#include "type/bank-access.h"
29#include "type/bank-type.h" // bank_memory_t
33
34namespace simics {
35
36/*
37 * Given two ranges [r1_start, r1_end) and [r2_start, r2_end),
38 * return the overlap range [o_start, o_end)
39 */
40std::pair<size_t, size_t> overlap_range(size_t r1_start,
41 size_t r1_end,
42 size_t r2_start,
43 size_t r2_end);
44
46
47enum class Inquiry : bool {
48 Inquiry = true,
49 NonInquiry = false
50};
51
52class MappableConfObject;
53
54/*
55 * A bank with default behavior
56 *
57 * The default behavior is to allow access to any offset, without any
58 * side-effects. Registers and fields don't have to be mapped as all reads
59 * return zero and all writes are ignored.
60 */
61// coverity[rule_of_five_violation:FALSE]
62class Bank : public BankInterface,
63 public HierarchicalObject {
64 public:
65 // @param name is the bank name alone, e.g., b0
66 Bank(MappableConfObject *dev_obj, const std::string &name)
69 }
70
71 // @param byte_order represents to byte endianness
72 Bank(MappableConfObject *dev_obj, const std::string &name,
73 ByteOrder byte_order)
74 : Bank(dev_obj, name) {
75 byte_order_ = byte_order;
76 }
77
78 // No duplication
79 Bank(const Bank&) = delete;
80 Bank& operator=(const Bank&) = delete;
81
82 /* coverity[rule_of_five] copy ctor and assignment already deleted*/
83 Bank(Bank &&rhs)
84 : HierarchicalObject(std::move(rhs)),
85 byte_order_(rhs.byte_order_),
86 regs_(std::move(rhs.regs_)),
87 newd_regs_(std::move(rhs.newd_regs_)),
88 callbacks_(rhs.callbacks_),
89 allocated_memory_(rhs.allocated_memory_) {
91 rhs.callbacks_ = nullptr;
92 rhs.allocated_memory_ = nullptr;
93 }
94 /* coverity[rule_of_five] copy ctor and assignment already deleted*/
96 // check for self-assignment
97 if (this == &rhs)
98 return *this;
99
100 HierarchicalObject::operator=(std::move(rhs));
102 byte_order_ = rhs.byte_order_;
103 regs_ = std::move(rhs.regs_);
104 newd_regs_ = std::move(rhs.newd_regs_);
105 callbacks_ = rhs.callbacks_;
106 rhs.callbacks_ = nullptr;
107 allocated_memory_ = rhs.allocated_memory_;
108 rhs.allocated_memory_ = nullptr;
109 return *this;
110 }
111
112 // BankInterface
113 std::string_view name() const override {
115 }
116 MappableConfObject *dev_obj() const override {
118 }
119 const std::string &description() const override {
121 }
122 void set_description(std::string_view desc) override {
124 }
125 void add_register(const register_t &reg) override;
126 void add_register(std::string_view name, std::string_view desc,
127 Offset offset, ByteSize number_of_bytes,
128 InitValue init_value,
129 const std::vector<field_t> &fields) override;
130 unsigned number_of_registers() const override {return regs_.size();}
131 std::pair<size_t, RegisterInterface *> register_at_index(
132 unsigned index) const override;
133 const std::map<size_t,
135 void set_callbacks(BankIssueCallbacksInterface *callbacks) override {
136 callbacks_ = callbacks;
137 }
138 ByteOrder get_byte_order() const override {return byte_order_;}
139 void set_miss_pattern(uint8_t miss_pattern) override {
140 miss_pattern_ = miss_pattern;
141 }
143 uint64_t offset) override;
144
145 protected:
146 // Read/Get implementation
147 virtual std::vector<uint8_t> read(
148 uint64_t offset, size_t size,
149 Inquiry inquiry = Inquiry::NonInquiry) const;
150 // Write/Set implementation
151 virtual void write(uint64_t offset, const std::vector<uint8_t> &value,
152 size_t size,
153 Inquiry inquiry = Inquiry::NonInquiry) const;
154
155 virtual void unmapped_read(size_t offset, size_t size) const;
156 virtual void unmapped_write(size_t offset, size_t size) const;
157
158 // Allocate bank memory by name
159 void allocate_bank_memory(std::string_view name);
160
161 private:
162 // Handle the bank instrumentation and forward the access to mapped
163 // registers
164 void read_access(BankAccess &access, // NOLINT
165 std::vector<uint8_t> &bytes) const; // NOLINT
166 void write_access(BankAccess &access, // NOLINT
167 std::vector<uint8_t> &bytes) const; // NOLINT
168
169 // Return if the input range overlaps with the existing range
170 bool has_range_overlap(uint64_t offset, uint64_t size) const;
171
172 // Little endianness is by default used
173 ByteOrder byte_order_ {ByteOrder::LE};
174
175 // Each missed byte in a miss read is set to this value
176 std::optional<uint8_t> miss_pattern_;
177
178 // Map associates offset to the corresponding register interface
179 std::map<size_t, RegisterInterface *> regs_;
180
181 // @internal: Keep track of heap allocated register objects
182 std::vector<std::unique_ptr<RegisterInterface>> newd_regs_;
183
184 // @internal: Used to issue a specific type of callbacks
185 const BankIssueCallbacksInterface *callbacks_ {nullptr};
186
187 // @internal: Keeps track of allocated bank memory
188 bank_memory_t *allocated_memory_ {nullptr};
189};
190
191} // namespace simics
192
193#endif
struct transaction transaction_t
Definition: bank-interface.h:30
Definition: bank-interface.h:45
Definition: bank-issue-callbacks-interface.h:31
Definition: bank.h:63
void set_miss_pattern(uint8_t miss_pattern) override
Definition: bank.h:139
Bank(MappableConfObject *dev_obj, const std::string &name, ByteOrder byte_order)
Definition: bank.h:72
virtual std::vector< uint8_t > read(uint64_t offset, size_t size, Inquiry inquiry=Inquiry::NonInquiry) const
void allocate_bank_memory(std::string_view name)
std::string_view name() const override
Definition: bank.h:113
Bank & operator=(const Bank &)=delete
exception_type_t transaction_access(transaction_t *t, uint64_t offset) override
Bank(MappableConfObject *dev_obj, const std::string &name)
Definition: bank.h:66
MappableConfObject * dev_obj() const override
Definition: bank.h:116
void add_register(const register_t &reg) override
void add_register(std::string_view name, std::string_view desc, Offset offset, ByteSize number_of_bytes, InitValue init_value, const std::vector< field_t > &fields) override
virtual void unmapped_read(size_t offset, size_t size) const
unsigned number_of_registers() const override
Definition: bank.h:130
void set_callbacks(BankIssueCallbacksInterface *callbacks) override
Definition: bank.h:135
Bank & operator=(Bank &&rhs)
Definition: bank.h:95
ByteOrder get_byte_order() const override
Definition: bank.h:138
virtual void unmapped_write(size_t offset, size_t size) const
Bank(const Bank &)=delete
void set_description(std::string_view desc) override
Definition: bank.h:122
const std::string & description() const override
Definition: bank.h:119
std::pair< size_t, RegisterInterface * > register_at_index(unsigned index) const override
Bank(Bank &&rhs)
Definition: bank.h:83
const std::map< size_t, RegisterInterface * > & mapped_registers() const override
virtual void write(uint64_t offset, const std::vector< uint8_t > &value, size_t size, Inquiry inquiry=Inquiry::NonInquiry) const
Definition: hierarchical-object.h:43
void init_iface(BankInterface *iface)
Definition: hierarchical-object.h:113
HierarchicalObject & operator=(const HierarchicalObject &)=delete
std::string_view name() const override
Definition: hierarchical-object.h:147
const std::string & description() const override
Definition: hierarchical-object.h:156
void set_description(std::string_view desc) override
Definition: hierarchical-object.h:160
MappableConfObject * dev_obj() const override
Definition: hierarchical-object.h:177
Definition: mappable-conf-object.h:131
Definition: register-interface.h:36
Literal type that extends size_t type.
Definition: common-types.h:27
Definition: attr-value.h:23
std::unordered_map< Offset, uint8_t > bank_memory_t
Definition: bank-type.h:48
ByteOrder
Definition: bank-interface.h:34
std::pair< size_t, size_t > overlap_range(size_t r1_start, size_t r1_end, size_t r2_start, size_t r2_end)
std::tuple< Name, Description, Offset, ByteSize, InitValue, std::vector< field_t > > register_t
Definition: register-type.h:45
Inquiry
Definition: bank.h:47
Definition: common-types.h:63
Definition: bank-access.h:43