Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/common/util/range_lut.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ template <typename T> inline std::string range_lut<T>::toString() const {
break;
case END_RANGE:
buf << " to 0x" << std::setw(sizeof(uint64_t) * 2) << std::setfill('0') << std::uppercase << std::hex << iter->first << std::dec
<< " as " << iter->second->index << std::endl;
<< " as " << iter->second.index << std::endl;
}
}
return buf.str();
Expand Down
6 changes: 6 additions & 0 deletions src/components/scc/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define _SYSC_MEMORY_H_

// Needed for the simple_target_socket
#include <tlm/scc/memory_map_collector.h>
#include <tlm_core/tlm_2/tlm_generic_payload/tlm_gp.h>
#ifndef SC_INCLUDE_DYNAMIC_PROCESSES
#define SC_INCLUDE_DYNAMIC_PROCESSES
Expand Down Expand Up @@ -201,6 +202,11 @@ memory<SIZE, BUSWIDTH, PAGE_ADDR_BITS, USE_CYCLES>::memory(const sc_core::sc_mod
operation_cb ? operation_cb(*this, gp, delay) : handle_operation(gp, delay);
});
target.register_transport_dbg([this](tlm::tlm_generic_payload& gp) -> unsigned {
if(gp.get_command() == tlm::TLM_IGNORE_COMMAND)
if(auto ext = gp.get_extension<tlm::scc::memory_map_extension>()) {
ext->node.name = name();
return 0;
}
sc_core::sc_time z = sc_core::SC_ZERO_TIME;
if(auto ext = gp.get_extension<host_mem_map_extension>()) {
if(ext->ptr)
Expand Down
8 changes: 8 additions & 0 deletions src/components/scc/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <scc/traceable.h>
#include <scc/tracer_base.h>
#include <scc/utilities.h>
#include <sysc/kernel/sc_object.h>
#ifdef _MSC_VER
#include <functional>
#else
Expand Down Expand Up @@ -115,6 +116,12 @@ template <typename DATATYPE> class sc_register : public sc_core::sc_object, publ
* @return true if this component shall be traced
*/
bool is_trace_enabled() const override { return enable_tracing.get_value(); }
/**
* @brief return the name of the resource
*
* @return the name
*/
char const* full_name() const override { return name(); };
/**
* @fn size_t size()const
* @brief get the size of this register in bytes
Expand Down Expand Up @@ -483,6 +490,7 @@ template <typename DATATYPE, size_t SIZE> struct sc_register_mem : public indexe
private:
struct mem_wrapper : public resource_access_if {
~mem_wrapper() = default;
char const* full_name() const override { return "memory"; };
std::size_t size() const override { return sizeof(DATATYPE); };
void reset() override { elem = 0; };
bool write(const uint8_t* data, std::size_t length, uint64_t offset, sc_core::sc_time& d) override {
Expand Down
7 changes: 6 additions & 1 deletion src/components/scc/resource_access_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ class resource_access_if {
public:
virtual ~resource_access_if() = default;
/**
* @fn std::size_t size()const =0
* @brief return the name of the resource
*
* @return the name
*/
virtual char const* full_name() const = 0;
/**
* @brief return the size of the resource
*
* @return the size
Expand Down
31 changes: 30 additions & 1 deletion src/components/scc/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
#include <scc/report.h>
#include <scc/utilities.h>
#include <sysc/utils/sc_vector.h>
#include <tlm.h>
#include <tlm/scc/initiator_mixin.h>
#include <tlm/scc/memory_map_collector.h>
#include <tlm/scc/scv/tlm_rec_initiator_socket.h>
#include <tlm/scc/scv/tlm_rec_target_socket.h>
#include <tlm/scc/target_mixin.h>
#include <tlm>
#include <unordered_map>
#include <util/range_lut.h>

Expand Down Expand Up @@ -322,6 +323,33 @@ bool router<BUSWIDTH, TARGET_SOCKET_TYPE>::get_direct_mem_ptr(int i, tlm::tlm_ge
}
template <unsigned BUSWIDTH, typename TARGET_SOCKET_TYPE>
unsigned router<BUSWIDTH, TARGET_SOCKET_TYPE>::transport_dbg(int i, tlm::tlm_generic_payload& trans) {
if(trans.get_command() == tlm::TLM_IGNORE_COMMAND) {
if(auto ext = trans.get_extension<tlm::scc::memory_map_extension>()) {
ext->node.name = name();
auto start_addr = ext->node.start;
for(auto e : addr_decoder) {
auto addr = ext->offset + e.first;
auto entry = e.second;
switch(entry.type) {
case util::range_lut<unsigned>::BEGIN_RANGE:
start_addr = addr;
break;
case util::range_lut<unsigned>::SINGLE_BYTE_RANGE:
start_addr = addr;
case util::range_lut<unsigned>::END_RANGE: {
ext->node.elemets.emplace_back(start_addr, ext->offset + addr);
auto new_ext = tlm::scc::memory_map_extension(ext->node.elemets.back());
new_ext.offset = start_addr;
trans.set_extension(&new_ext);
initiator[entry.index]->transport_dbg(trans);
trans.set_extension(ext);
break;
}
}
}
return 0;
}
}
::sc_dt::uint64 address = trans.get_address();
if(ibases[i]) {
address += ibases[i];
Expand Down Expand Up @@ -360,6 +388,7 @@ void router<BUSWIDTH, TARGET_SOCKET_TYPE>::invalidate_direct_mem_ptr(int id, ::s
}
template <unsigned BUSWIDTH, typename TARGET_SOCKET_TYPE> void router<BUSWIDTH, TARGET_SOCKET_TYPE>::end_of_elaboration() {
addr_decoder.validate();
SCCDEBUG(SCOBJ) << "address map\n" << addr_decoder.toString();
}

} // namespace scc
Expand Down
30 changes: 27 additions & 3 deletions src/components/scc/tlm_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#define _SYSC_TLM_TARGET_H_

#include "resource_access_if.h"
#include <array>
#include <numeric>
#include <scc/utilities.h>
#include <tlm/scc/memory_map_collector.h>
#include <tlm/scc/scv/tlm_rec_target_socket.h>
#include <tlm/scc/target_mixin.h>
#include <tlm_core/tlm_2/tlm_generic_payload/tlm_gp.h>
#include <util/range_lut.h>

namespace scc {
Expand Down Expand Up @@ -107,7 +107,8 @@ template <unsigned int BUSWIDTH = LT, unsigned int ADDR_UNIT_BITWIDTH = 8> class
tlm::tlm_generic_payload* current_payload{nullptr};

protected:
util::range_lut<std::pair<resource_access_if*, uint64_t>> socket_map;
using resource_access_t = std::pair<resource_access_if*, uint64_t>;
util::range_lut<resource_access_t> socket_map;
template <typename T> T* get_payload_extension() {
if(current_payload)
return current_payload->get_extension<T>();
Expand Down Expand Up @@ -221,6 +222,29 @@ void scc::tlm_target<BUSWIDTH, ADDR_UNIT_BITWIDTH>::b_tranport_cb(tlm::tlm_gener

template <unsigned int BUSWIDTH, unsigned int ADDR_UNIT_BITWIDTH>
unsigned int scc::tlm_target<BUSWIDTH, ADDR_UNIT_BITWIDTH>::tranport_dbg_cb(tlm::tlm_generic_payload& gp) {
if(gp.get_command() == tlm::TLM_IGNORE_COMMAND)
if(auto ext = gp.get_extension<tlm::scc::memory_map_extension>()) {
std::string name = socket.name();
ext->node.name = name.substr(0, name.length() - strlen(socket.basename()) - 1);
auto start_addr = ext->node.start;
for(auto e : socket_map) {
auto addr = ext->offset + e.first;
auto entry = e.second;
switch(entry.type) {
case util::range_lut<resource_access_t>::BEGIN_RANGE:
start_addr = addr;
break;
case util::range_lut<resource_access_t>::SINGLE_BYTE_RANGE:
start_addr = addr;
case util::range_lut<resource_access_t>::END_RANGE: {
ext->node.elemets.emplace_back(start_addr, ext->offset + addr);
ext->node.elemets.back().name = entry.index.first->full_name();
break;
}
}
}
return 0;
}
resource_access_if* ra = nullptr;
uint64_t base = 0;
std::tie(ra, base) = socket_map.getEntry(gp.get_address());
Expand Down
6 changes: 5 additions & 1 deletion src/components/scc/tlm_target_bfs_register_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ template <typename datatype_t> class bitfield_register : public sc_core::sc_obje
, writeMask{writeMask}
, readMask{readMask} {}

/**
* @return the name
*/
char const* full_name() const override { return name(); };
/**
* @return The size of the register in bytes
*/
constexpr size_t size() const noexcept override { return sizeof(datatype_t); }
size_t size() const noexcept override { return sizeof(datatype_t); }

void reset() override { storage = resetValue; }

Expand Down
75 changes: 75 additions & 0 deletions src/sysc/tlm/scc/memory_map_collector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright 2016, 2018 MINRES Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/

#ifndef _TLM_SCC_MEMORY_MAP_COLLECTOR_H_
#define _TLM_SCC_MEMORY_MAP_COLLECTOR_H_

#include <cstdint>
#include <fmt/format.h>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <tlm>
#include <tlm_core/tlm_2/tlm_2_interfaces/tlm_fw_bw_ifs.h>

//! @brief SystemC TLM
namespace tlm {
//! @brief SCC TLM utilities
namespace scc {
struct memory_node {
uint64_t start{0};
uint64_t end{std::numeric_limits<uint64_t>::max()};
std::string name;
std::vector<memory_node> elemets;
memory_node(uint64_t start, uint64_t end)
: start(start)
, end(end) {}
memory_node() = default;
std::string to_string(std::string const& prefix = "") const {
std::ostringstream os;
std::string filler(16 - prefix.length(), ' ');
os << fmt::format("{} 0x{:016x}:0x{:016x}{}{}\n", prefix, start, end, filler, name);
for(auto e : elemets)
os << e.to_string(prefix + " ");
return os.str();
}
};

struct memory_map_extension : tlm::tlm_extension<memory_map_extension> {
tlm_extension_base* clone() const override { return new memory_map_extension(*this); }
void copy_from(tlm_extension_base const& from) override { throw std::runtime_error("copying of memory_map_extension not allowed"); }

memory_map_extension(memory_node& node)
: node(node) {}
~memory_map_extension() {}

memory_node& node;
uint64_t offset{0};
};

template <typename TYPES = tlm::tlm_base_protocol_types>
memory_node gather_memory(sc_core::sc_port_b<tlm::tlm_fw_transport_if<TYPES>>& port) {
memory_node root;
auto ext = memory_map_extension(root);
/*TYPES::tlm_payload_type*/ tlm::tlm_generic_payload trans;
trans.set_extension(&ext);
port->transport_dbg(trans);
trans.set_extension<memory_map_extension>(nullptr);
return std::move(root);
}
} // namespace scc
} // namespace tlm
#endif // _TLM_SCC_MEMORY_MAP_COLLECTOR_H_
21 changes: 11 additions & 10 deletions src/sysc/tlm/scc/tlm_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ namespace tlm {
namespace scc {

struct tlm_id_extension : public tlm_extension<tlm_id_extension> {
virtual tlm_extension_base* clone() const {
auto* t = new tlm_id_extension(this->id);
return t;
}
virtual void copy_from(tlm_extension_base const& from) { id = static_cast<tlm_id_extension const&>(from).id; }
tlm_extension_base* clone() const override { return new tlm_id_extension(this->id); }
void copy_from(tlm_extension_base const& from) override { id = static_cast<tlm_id_extension const&>(from).id; }
tlm_id_extension(tlm_gp_shared_ptr& i)
: tlm_id_extension(reinterpret_cast<uintptr_t>(i.get())) {}
tlm_id_extension(void* i)
Expand Down Expand Up @@ -65,13 +62,17 @@ inline void setId(tlm::tlm_generic_payload& gp, uintptr_t id) {
}

struct initiator_id_extension : public tlm_extension<tlm_id_extension> {
virtual tlm_extension_base* clone() const {
auto* t = new initiator_id_extension(this->id);
return t;
}
virtual void copy_from(tlm_extension_base const& from) {}
tlm_extension_base* clone() const override { return new initiator_id_extension(*this); }
void copy_from(tlm_extension_base const& from) override {}

initiator_id_extension(uint64_t i)
: id(i) {}

initiator_id_extension(initiator_id_extension const& o)
: id(o.id) {}

virtual ~initiator_id_extension() = default;

const uint64_t id;
};

Expand Down