qualcomm/qbox
Loading...
Searching...
No Matches
router_if.h
1/*
2 * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
3 * Author: GreenSocs 2022
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#ifndef _GREENSOCS_BASE_COMPONENTS_ROUTER_IF_H
9#define _GREENSOCS_BASE_COMPONENTS_ROUTER_IF_H
10
11#include <systemc>
12#include <tlm>
13#include <scp/report.h>
14#include <scp/helpers.h>
15#include <tlm_utils/multi_passthrough_initiator_socket.h>
16#include <tlm_utils/multi_passthrough_target_socket.h>
17#include <tlm_sockets_buswidth.h>
18#include <string>
19#include <memory>
20#include <vector>
21
22namespace gs {
23template <unsigned int BUSWIDTH = DEFAULT_TLM_BUSWIDTH>
25{
26protected:
27 template <typename MOD>
28 class multi_passthrough_initiator_socket_spying
29 : public tlm_utils::multi_passthrough_initiator_socket<MOD, BUSWIDTH>
30 {
31 using typename tlm_utils::multi_passthrough_initiator_socket<MOD, BUSWIDTH>::base_target_socket_type;
32
33 const std::function<void(std::string)> register_cb;
34
35 public:
36 multi_passthrough_initiator_socket_spying(const char* name, const std::function<void(std::string)>& f)
37 : tlm_utils::multi_passthrough_initiator_socket<MOD, BUSWIDTH>::multi_passthrough_initiator_socket(name)
38 , register_cb(f)
39 {
40 }
41
42 void bind(base_target_socket_type& socket)
43 {
44 tlm_utils::multi_passthrough_initiator_socket<MOD, BUSWIDTH>::bind(socket);
45 register_cb(socket.get_base_export().name());
46 }
47 };
48
49public:
50 struct target_info {
51 size_t index;
52 std::string name;
53 sc_dt::uint64 address;
54 sc_dt::uint64 size;
55 uint32_t priority;
56 bool use_offset;
57 bool is_callback;
58 bool chained;
59 std::string shortname;
60 // 1D bank fields (used when dim_strides is empty).
61 // stride == 0 means plain range (scalar / contiguous register).
62 sc_dt::uint64 stride = 0;
63 sc_dt::uint64 elem_size = 0;
64 // N-D bank layout, outer dim first. Non-empty overrides the 1D fields.
65 std::vector<sc_dt::uint64> dim_strides;
66 std::vector<sc_dt::uint64> dim_counts;
67
68 bool claims(sc_dt::uint64 addr) const
69 {
70 if (addr < address || (addr - address) >= size) return false;
71 if (!dim_strides.empty()) {
72 sc_dt::uint64 r = addr - address;
73 for (size_t k = 0; k < dim_strides.size(); k++) {
74 sc_dt::uint64 idx = r / dim_strides[k];
75 if (idx >= dim_counts[k]) return false;
76 r = r % dim_strides[k];
77 }
78 return r < elem_size;
79 }
80 if (stride == 0) return true;
81 return ((addr - address) % stride) < elem_size;
82 }
83 };
84
85 void rename_last(std::string s)
86 {
87 auto ti = bound_targets.back();
88 ti->name = s;
89 }
90
91 std::vector<std::shared_ptr<target_info>> get_bound_targets() { return bound_targets; } // Returns shared_ptrs
92
93 virtual ~router_if() = default;
94
95protected:
96 std::string parent(std::string name) { return name.substr(0, name.find_last_of('.')); }
97
98 /* NB use the EXPORT name, so as not to be hassled by the _port_0*/
99 std::string nameFromSocket(std::string s) { return s; }
100
101 virtual void register_boundto(std::string s) = 0;
102
103 virtual std::shared_ptr<target_info> decode_address(tlm::tlm_generic_payload& trans) = 0; // Returns shared_ptr
104
105 virtual void lazy_initialize() = 0;
106
107 std::vector<std::shared_ptr<target_info>> bound_targets; // Changed to shared_ptr
108};
109} // namespace gs
110
111#endif
Definition router_if.h:25
Tool which reads a Lua configuration file and sets parameters.
Definition biflow.cc:10
Definition router_if.h:50