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 <map>
20#include <memory>
21#include <optional>
22#include <string>
23#include <string_view>
24#include <utility>
25#include <vector>
26
32#include "simics/type/bank-type.h" // bank_memory_t
33
34namespace simics {
35
36class MappableConfObject;
37
38enum class Inquiry : bool {
39 Inquiry = true,
40 NonInquiry = false
41};
42
50class Bank : public BankInterface,
51 public HierarchicalObject {
52 public:
54 Bank(MappableConfObject *dev_obj, const std::string &name);
55
57 Bank(MappableConfObject *dev_obj, const std::string &name,
58 ByteOrder byte_order);
59
60 // No duplication
61 Bank(const Bank&) = delete;
62 Bank& operator=(const Bank&) = delete;
63
64 Bank(Bank &&rhs);
66
67 virtual ~Bank() = default;
68
69 // BankInterface
70 std::string_view name() const override {
72 }
73 MappableConfObject *dev_obj() const override {
75 }
76 const std::string &description() const override {
78 }
79 void set_description(std::string_view desc) override {
81 }
82 void add_register(const register_t &reg) override;
83 void add_register(std::string_view name, std::string_view desc,
84 Offset offset, ByteSize number_of_bytes,
85 InitValue init_value,
86 const std::vector<field_t> &fields) override;
87 unsigned number_of_registers() const override;
88 std::pair<size_t, RegisterInterface *> register_at_index(
89 unsigned index) const override;
90 const std::map<size_t,
91 RegisterInterface *> &mapped_registers() const override;
92 void set_callbacks(BankIssueCallbacksInterface *callbacks) override {
93 callbacks_ = callbacks;
94 }
95 ByteOrder get_byte_order() const override {return byte_order_;}
96 void set_miss_pattern(uint8_t miss_pattern) override {
97 miss_pattern_ = miss_pattern;
98 }
99 exception_type_t transaction_access(transaction_t *t,
100 uint64_t offset) override;
101
102 protected:
103 // Read/Get implementation
104 virtual std::vector<uint8_t> read(
105 uint64_t offset, size_t size,
106 Inquiry inquiry = Inquiry::NonInquiry) const;
107 // Write/Set implementation
108 virtual void write(uint64_t offset, const std::vector<uint8_t> &value,
109 size_t size,
110 Inquiry inquiry = Inquiry::NonInquiry) const;
111
112 virtual void unmapped_read(size_t offset, size_t size) const;
113 virtual void unmapped_write(size_t offset, size_t size) const;
114
116 void allocate_bank_memory(std::string_view name);
117
118 private:
119 // Handle the bank instrumentation and forward the access to mapped
120 // registers
121 void read_access(BankAccess &access, // NOLINT
122 std::vector<uint8_t> &bytes) const; // NOLINT
123 void write_access(BankAccess &access, // NOLINT
124 std::vector<uint8_t> &bytes) const; // NOLINT
125
126 // Return if the input range overlaps with the existing range
127 bool has_range_overlap(uint64_t offset, size_t size) const;
128
130 void set_iface();
131
132 // Little endianness is by default used
133 ByteOrder byte_order_ {ByteOrder::LE};
134
135 // Each missed byte in a miss read is set to this value
136 std::optional<uint8_t> miss_pattern_;
137
138 // Map associates offset to the corresponding register interface
139 std::map<size_t, RegisterInterface *> regs_;
140
141 // @internal: Keep track of heap allocated register objects
142 std::vector<std::unique_ptr<RegisterInterface>> newd_regs_;
143
144 // @internal: Used to issue a specific type of callbacks
145 const BankIssueCallbacksInterface *callbacks_ {nullptr};
146
149 bank_memory_t *allocated_memory_ {nullptr};
150};
151
152} // namespace simics
153
154#endif
An interface implemented by a Simics bank.
Definition: bank-interface.h:47
Definition: bank-issue-callbacks-interface.h:25
Base class to represent a Simics register bank.
Definition: bank.h:51
void set_miss_pattern(uint8_t miss_pattern) override
Set the miss pattern for the bank.
Definition: bank.h:96
Bank(MappableConfObject *dev_obj, const std::string &name, ByteOrder byte_order)
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)
Allocate memory for this bank by name.
std::string_view name() const override
Get the name of the bank without level delimiters.
Definition: bank.h:70
Bank & operator=(const Bank &)=delete
exception_type_t transaction_access(transaction_t *t, uint64_t offset) override
Entry point for a memory access from the transaction interface.
virtual ~Bank()=default
Bank(MappableConfObject *dev_obj, const std::string &name)
MappableConfObject * dev_obj() const override
Get the device object.
Definition: bank.h:73
void add_register(const register_t &reg) override
Parse a register name and add register to the bank.
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
Add a register to the bank.
virtual void unmapped_read(size_t offset, size_t size) const
unsigned number_of_registers() const override
Get the number of registers in the bank.
void set_callbacks(BankIssueCallbacksInterface *callbacks) override
Set the callbacks for bank issues.
Definition: bank.h:92
Bank & operator=(Bank &&rhs)
ByteOrder get_byte_order() const override
Get the byte order of the bank.
Definition: bank.h:95
virtual void unmapped_write(size_t offset, size_t size) const
Bank(const Bank &)=delete
void set_description(std::string_view desc) override
Set the description for the bank.
Definition: bank.h:79
const std::string & description() const override
Get the description of the bank.
Definition: bank.h:76
std::pair< size_t, RegisterInterface * > register_at_index(unsigned index) const override
Get the register at a specific index.
Bank(Bank &&rhs)
const std::map< size_t, RegisterInterface * > & mapped_registers() const override
Get all mapped registers on the bank ordered by offset.
virtual void write(uint64_t offset, const std::vector< uint8_t > &value, size_t size, Inquiry inquiry=Inquiry::NonInquiry) const
Base class for Bank, Register, and Field classes.
Definition: hierarchical-object.h:44
std::string_view name() const override
const std::string & description() const override
void set_description(std::string_view desc) override
MappableConfObject * dev_obj() const override
Definition: mappable-conf-object.h:134
Definition: register-interface.h:37
Literal type that extends size_t type.
Definition: common-types.h:30
Definition: after-bank.h:33
std::unordered_map< Offset, uint8_t > bank_memory_t
Definition: bank-type.h:52
ByteOrder
Definition: bank-interface.h:33
std::tuple< Name, Description, Offset, ByteSize, InitValue, std::vector< field_t > > register_t
Definition: register-type.h:45
Inquiry
Definition: bank.h:38
Definition: bank-access.h:42