aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2023-10-30 23:02:37 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2023-10-30 23:02:37 +0100
commit3449e28b439e8d529ff41e466319292339757fe7 (patch)
tree6c770b53ff15819410b3f7012635466c840e1f0a /src
parent222fec65b199de8004e5664edd03ced4f29cdb94 (diff)
downloadsysc-playground-3449e28b439e8d529ff41e466319292339757fe7.tar.gz
sysc-playground-3449e28b439e8d529ff41e466319292339757fe7.zip
lt_bus: factor our computation of abs mmap address
Diffstat (limited to 'src')
-rw-r--r--src/models/lt_bus.h62
1 files changed, 32 insertions, 30 deletions
diff --git a/src/models/lt_bus.h b/src/models/lt_bus.h
index a8391f8..9b16ab9 100644
--- a/src/models/lt_bus.h
+++ b/src/models/lt_bus.h
@@ -104,22 +104,12 @@ class lt_bus : public sc_core::sc_module {
continue;
}
- // Compute absolute start address.
- const sc_dt::uint64 abs_start = map.addr.start + start;
- assert(abs_start <= map.addr.end);
-
- // Compute absolute end address. Limit if mapping range exceeded.
- const auto comp_abs_end = [&map](sc_dt::uint64 abs_end) -> sc_dt::uint64 {
- if (abs_end > map.addr.end /* exceeds mapping */ ||
- abs_end < map.addr.start /* wraps around */) {
- return map.addr.end;
- }
- return abs_end;
- };
- const sc_dt::uint64 abs_end = comp_abs_end(map.addr.start + end);
+ // Compute absolute start/end address based on memory map.
+ const range abs_addr =
+ compute_abs_mmap_address(range{start, end}, map.addr);
for (auto& sock : m_initiators) {
- (*sock)->invalidate_direct_mem_ptr(abs_start, abs_end);
+ (*sock)->invalidate_direct_mem_ptr(abs_addr.start, abs_addr.end);
}
}
}
@@ -155,23 +145,14 @@ class lt_bus : public sc_core::sc_module {
return false;
}
- // Compute absolute start address.
- const sc_dt::uint64 abs_start = r.start + dmi.get_start_address();
- assert(abs_start < r.end);
+ // Compute absolute start/end address based on memory map.
+ const range abs_addr = compute_abs_mmap_address(
+ range{dmi.get_start_address(), dmi.get_end_address()},
+ range{r.start, r.end});
- // Compute absolute end address. Limit if mapping range exceeded.
- const auto comp_abs_end = [&r](sc_dt::uint64 abs_end) -> sc_dt::uint64 {
- if (abs_end > r.end /* exceeds mapping */ ||
- abs_end < r.start /* wraps around */) {
- return r.end;
- }
- return abs_end;
- };
- const sc_dt::uint64 abs_end =
- comp_abs_end(r.start + dmi.get_end_address());
-
- dmi.set_start_address(abs_start);
- dmi.set_end_address(abs_end);
+ // Update dmi payload with absolute addresses.
+ dmi.set_start_address(abs_addr.start);
+ dmi.set_end_address(abs_addr.end);
return true;
}
@@ -218,6 +199,27 @@ class lt_bus : public sc_core::sc_module {
return decode(range{start, end});
}
+ // -- COMPUTE ABSOLUTE MEMORY MAP ADDRESS ------------------------------------
+
+ static range compute_abs_mmap_address(range rel, range map) {
+ // Compute absolute start address.
+ const sc_dt::uint64 abs_start = map.start + rel.start;
+ // Start address must be in bounds of the memory map mapping.
+ assert(abs_start <= map.end);
+
+ // Compute absolute end address. Limit by memory map if range exceeded.
+ const auto comp_abs_end = [&map](sc_dt::uint64 abs_end) -> sc_dt::uint64 {
+ if (abs_end > map.end /* exceeds mapping */ ||
+ abs_end < map.start /* wraps around */) {
+ return map.end;
+ }
+ return abs_end;
+ };
+ const sc_dt::uint64 abs_end = comp_abs_end(map.start + rel.end);
+
+ return range{abs_start, abs_end};
+ }
+
// -- SC_MODULE CALLBACKS ----------------------------------------------------
virtual void start_of_simulation() override {