25#include <l4/bid_config.h>
27#include <l4/cxx/minmax>
30#include <l4/sys/cxx/ipc_legacy>
32namespace L4Re {
namespace Util {
49 : _ds_start(0), _ds_size(0), _map_flags(L4::Ipc::Snd_fpage::Map),
50 _cache_flags(L4::Ipc::Snd_fpage::Cached)
68 int map(Dataspace::Offset offset,
69 Dataspace::Map_addr local_addr,
70 Dataspace::Flags flags,
71 Dataspace::Map_addr min_addr,
72 Dataspace::Map_addr max_addr,
80 if (!check_limit(offset))
83 printf(
"limit failed: off=%lx sz=%lx\n", offset, size());
97 if (map_base < _ds_start)
100 if (map_base + (1UL << (order + 1)) -1 > (_ds_start + round_size() - 1))
104 if (map_base < min_addr)
107 if (map_base + (1UL << (order + 1)) -1 > max_addr -1)
111 if (local_addr == ~0UL || ((addr ^ local_addr) & mask))
119 Dataspace::Map_addr b = map_base;
120 unsigned send_order = order;
121 int err =
map_hook(offset , order, flags,
147 virtual int map_hook([[maybe_unused]] Dataspace::Offset offs,
148 [[maybe_unused]]
unsigned order,
149 [[maybe_unused]] Dataspace::Flags flags,
150 [[maybe_unused]] Dataspace::Map_addr *base,
151 [[maybe_unused]]
unsigned *send_order)
189 [[maybe_unused]]
unsigned long size)
noexcept
203 virtual long clear(
unsigned long offs,
unsigned long size)
const noexcept
205 if (!check_limit(offs))
208 unsigned long sz = size = cxx::min(size, round_size() - offs);
212 unsigned long b_addr = _ds_start + offs;
213 unsigned long b_sz = cxx::min(size - offs, sz);
215 memset(
reinterpret_cast<void *
>(b_addr), 0, b_sz);
237 [[maybe_unused]]
unsigned access)
noexcept
271 [[maybe_unused]]
l4_addr_t &end_addr)
noexcept
275 long op_map(L4Re::Dataspace::Rights rights,
276 L4Re::Dataspace::Offset offset,
277 L4Re::Dataspace::Map_addr spot,
278 L4Re::Dataspace::Flags flags,
281 auto rf = map_flags(rights);
283 if (!rf.w() && flags.w())
286 return map(offset, spot, flags & rf, 0, ~0, fp);
289 long op_allocate(L4Re::Dataspace::Rights rights,
290 L4Re::Dataspace::Offset offset,
291 L4Re::Dataspace::Size size)
292 {
return allocate(offset, size, rights & 3); }
294 long op_copy_in(L4Re::Dataspace::Rights rights,
295 L4Re::Dataspace::Offset dst_offs,
297 L4Re::Dataspace::Offset src_offs,
298 L4Re::Dataspace::Size sz)
309 return copy(dst_offs, src_cap.
data(), src_offs, sz);
316 s.
flags = Dataspace::Flags(0);
317 if (map_flags(rights).w())
322 long op_clear(L4Re::Dataspace::Rights rights,
323 L4Re::Dataspace::Offset offset,
324 L4Re::Dataspace::Size size)
326 if (!map_flags(rights).w())
329 return clear(offset, size);
332 long op_map_info(L4Re::Dataspace::Rights,
339 return map_info(start_addr, end_addr);
344 unsigned long size() const noexcept
346 unsigned long map_flags() const noexcept
347 {
return _map_flags; }
348 unsigned long page_size() const noexcept
350 unsigned long round_size() const noexcept
352 bool check_limit(
l4_addr_t offset)
const noexcept
353 {
return offset < round_size(); }
355 L4Re::Dataspace::Flags
356 map_flags(L4Re::Dataspace::Rights rights =
L4_CAP_FPAGE_W)
const noexcept
366 void size(
unsigned long size)
noexcept { _ds_size = size; }
371 Cache_type _cache_flags;
372 L4Re::Dataspace::Flags _rw_flags;
Interface for memory-like objects.
virtual long map_info(l4_addr_t &start_addr, l4_addr_t &end_addr) noexcept
Return mapping information for no-MMU systems.
virtual unsigned long page_shift() const noexcept
Define the size of the flexpage to map.
virtual void take() noexcept
Take a reference to this dataspace.
int map(Dataspace::Offset offset, Dataspace::Map_addr local_addr, Dataspace::Flags flags, Dataspace::Map_addr min_addr, Dataspace::Map_addr max_addr, L4::Ipc::Snd_fpage &memory)
Map a region of the dataspace.
virtual long allocate(l4_addr_t offset, l4_size_t size, unsigned access) noexcept
Allocate a region within a dataspace.
virtual int map_hook(Dataspace::Offset offs, unsigned order, Dataspace::Flags flags, Dataspace::Map_addr *base, unsigned *send_order)
A hook that is called for acquiring the data to be mapped.
virtual long clear(unsigned long offs, unsigned long size) const noexcept
Clear a region in the dataspace.
virtual unsigned long release() noexcept
Release a reference to this dataspace.
virtual long copy(l4_addr_t dst_offs, l4_umword_t src_id, l4_addr_t src_offs, unsigned long size) noexcept
Copy from src dataspace to this destination dataspace.
virtual bool is_static() const noexcept
Return whether the dataspace is static.
bool id_received() const noexcept
Check if a label was received instead of a mapping.
Cacheopt
Caching options, see l4_fpage_cacheability_opt_t.
l4_umword_t data() const noexcept
Return the raw flex page descriptor.
Dataspace protocol defintion.
unsigned int l4_size_t
Unsigned size type.
unsigned long l4_umword_t
Unsigned machine word.
unsigned long l4_addr_t
Address type.
@ L4_EACCESS
Permission denied.
@ L4_EINVAL
Invalid argument.
@ L4_ENODEV
No such thing.
l4_fpage_t l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW
Create a memory flex page.
@ L4_CAP_FPAGE_W
Interface specific 'W' right for capability flex-pages.
l4_addr_t l4_trunc_page(l4_addr_t address) L4_NOTHROW
Round an address down to the next lower page boundary.
l4_addr_t l4_trunc_size(l4_addr_t address, unsigned char bits) L4_NOTHROW
Round an address down to the next lower flex page with size bits.
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
#define L4_PAGESHIFT
Size of a page, log2-based.
l4_addr_t l4_round_size(l4_addr_t value, unsigned char bits) L4_NOTHROW
Round value up to the next alignment with bits size.
Common L4 ABI Data Types.
@ Caching_mask
Mask for caching flags.
@ W
Request write-only mapping.
Information about the dataspace.