C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
bank-instrumentation-subscribe-connection.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2022 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_INSTRUMENTATION_SUBSCRIBE_CONNECTION_H
17#define SIMICS_BANK_INSTRUMENTATION_SUBSCRIBE_CONNECTION_H
18
19#include <simics/c++/model-iface/bank-instrumentation.h>
20#include <simics/c++/model-iface/instrumentation-provider.h>
21
22#include <cstdint>
23#include <map>
24#include <tuple>
25#include <utility>
26#include <vector>
27
29
30namespace simics {
31
32struct BankAccess;
33
34// Instrumentation connection and callback manager
35// According to API reference manual about "instrumentation_order":
36// The default order for callbacks that should be honored by all providers,
37// where possible, regardless if they implement the instrumentation_order
38// interface or not is:
39// 1. all anonymous connections, i.e. NULL connections,
40// 2. in registration order connection order, which if not re-ordered will be
41// the connection registration order
42// 3. callback registration order
44 : public iface::BankInstrumentationSubscribeInterface,
45 public iface::InstrumentationOrderInterface,
47 struct AfterRead {
48 uint64_t offset;
49 uint64_t size;
50 after_read_callback_t cb;
51 lang_void *user_data;
52 };
53 struct AfterWrite {
54 uint64_t offset;
55 uint64_t size;
56 after_write_callback_t cb;
57 lang_void *user_data;
58 };
59 struct BeforeRead {
60 uint64_t offset;
61 uint64_t size;
62 before_read_callback_t cb;
63 lang_void *user_data;
64 };
65 struct BeforeWrite {
66 uint64_t offset;
67 uint64_t size;
68 before_write_callback_t cb;
69 lang_void *user_data;
70 };
71 using ar_map = std::map<bank_callback_handle_t, AfterRead>;
72 using aw_map = std::map<bank_callback_handle_t, AfterWrite>;
73 using br_map = std::map<bank_callback_handle_t, BeforeRead>;
74 using bw_map = std::map<bank_callback_handle_t, BeforeWrite>;
75 using cb_tuple = std::tuple<bool, ar_map, aw_map, br_map, bw_map>;
76 using conf_obj_cb_pair = std::pair<conf_object_t *, cb_tuple>;
77 using vect_iter = std::vector<conf_obj_cb_pair>::iterator;
78
79 public:
82
83 // iface::BankInstrumentationInterface
84 bank_callback_handle_t register_after_read(
85 conf_object_t *connection, uint64 offset, uint64 size,
86 after_read_callback_t after_read, lang_void *user_data) override;
87 bank_callback_handle_t register_after_write(
88 conf_object_t *connection, uint64 offset, uint64 size,
89 after_write_callback_t after_write, lang_void *user_data) override;
90 bank_callback_handle_t register_before_read(
91 conf_object_t *connection, uint64 offset, uint64 size,
92 before_read_callback_t before_read, lang_void *user_data) override;
93 bank_callback_handle_t register_before_write(
94 conf_object_t *connection, uint64 offset, uint64 size,
95 before_write_callback_t before_write,
96 lang_void *user_data) override;
97 void remove_callback(bank_callback_handle_t callback) override;
98 void remove_connection_callbacks(conf_object_t *connection) override;
99 void enable_connection_callbacks(conf_object_t *connection) override;
100 void disable_connection_callbacks(conf_object_t *connection) override;
101
102 // iface::InstrumentationOrderInterface
103 attr_value_t get_connections() override;
104 bool move_before(conf_object_t *connection, conf_object_t *before) override;
105
106 // iface::BankIssueCallbacksInterface
107 void issue_callbacks(BankAccess *access, CallbackType type) const override;
108
109 // Helper functions
110 bool empty() const;
111 // The total number of callbacks saved
112 unsigned int number_of_callbacks() const;
113
114 private:
115 void init_connection_callbacks(conf_object_t *connection);
116 vect_iter find_connection(conf_object_t *connection);
117
118 // Initialized once and used inside each tool callback to monitor and
119 // modify the state of current accesses
120 bank_after_read_interface_t ar_iface_;
121 bank_after_write_interface_t aw_iface_;
122 bank_before_read_interface_t br_iface_;
123 bank_before_write_interface_t bw_iface_;
124
125 bank_callback_handle_t handle_ {0};
126 std::vector<conf_obj_cb_pair> connection_callbacks_;
127};
128
129} // namespace simics
130
131#endif
Definition: bank-instrumentation-subscribe-connection.h:46
bank_callback_handle_t register_after_write(conf_object_t *connection, uint64 offset, uint64 size, after_write_callback_t after_write, lang_void *user_data) override
void remove_callback(bank_callback_handle_t callback) override
bank_callback_handle_t register_before_write(conf_object_t *connection, uint64 offset, uint64 size, before_write_callback_t before_write, lang_void *user_data) override
bank_callback_handle_t register_before_read(conf_object_t *connection, uint64 offset, uint64 size, before_read_callback_t before_read, lang_void *user_data) override
void remove_connection_callbacks(conf_object_t *connection) override
void disable_connection_callbacks(conf_object_t *connection) override
void enable_connection_callbacks(conf_object_t *connection) override
void issue_callbacks(BankAccess *access, CallbackType type) const override
bank_callback_handle_t register_after_read(conf_object_t *connection, uint64 offset, uint64 size, after_read_callback_t after_read, lang_void *user_data) override
bool move_before(conf_object_t *connection, conf_object_t *before) override
Definition: bank-issue-callbacks-interface.h:25
Definition: after-bank.h:33
CallbackType
Definition: bank-issue-callbacks-interface.h:23
Definition: bank-access.h:42