2 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
13 #include <l4/sys/types.h>
14 #include <l4/cxx/list>
15 #include <l4/cxx/ipc_server>
16 #include <l4/cxx/ipc_stream>
17 #include <l4/re/dataspace>
19 #include "server_obj.h"
26 class Dataspace : public Server_object, public Q_object
32 Read_only = L4Re::Dataspace::Map_ro,
33 Writable = L4Re::Dataspace::Map_rw,
42 Address(long error) throw() : offs(-1UL) { fpage.raw = error; }
44 Address(l4_addr_t base, l4_addr_t size, Ds_rw rw = Read_only,
45 l4_addr_t offs = 0) throw()
46 : fpage(l4_fpage(base, size, rw ? L4_FPAGE_RWX : L4_FPAGE_RX)),
49 unsigned long bs() const throw() { return fpage.raw & ~((1 << 12)-1); }
50 unsigned long sz() const throw() { return 1 << l4_fpage_size(fpage); }
51 unsigned long of() const throw() { return offs; }
52 l4_fpage_t fp() const throw() { return fpage; }
54 template< typename T >
55 T adr() const throw() { return (T)(bs() + offs); }
57 void *adr() const throw() { return (void*)(bs() + offs); }
59 bool is_nil() const throw() { return offs == -1UL; }
61 * \brief Get the error code that led to the invalid address.
62 * \pre is_nil() must return true.
64 long error() const throw() { return fpage.raw; }
68 Dataspace(unsigned long size, unsigned long flags = 0) throw()
69 : _size(size), _flags(flags)
73 unsigned long size() const throw() { return _size; }
74 virtual void unmap(bool ro = false) const throw() = 0;
75 virtual Address address(l4_addr_t ds_offset,
76 Ds_rw rw = Writable, l4_addr_t hot_spot = 0,
77 l4_addr_t min = 0, l4_addr_t max = ~0) const = 0;
79 virtual int pre_allocate(l4_addr_t offset, l4_size_t size, unsigned rights) = 0;
81 unsigned long is_writable() const throw() { return _flags & Writable; }
82 unsigned long can_cow() const throw() { return _flags & Cow_enabled; }
83 unsigned long flags() const throw() { return _flags; }
84 virtual ~Dataspace() {}
86 virtual unsigned long page_shift() const throw() = 0;
87 unsigned long page_size() const throw() { return 1UL << page_shift(); }
89 virtual bool is_static() const throw() = 0;
90 virtual long clear(unsigned long offs, unsigned long size) const throw();
93 void size(unsigned long size) throw() { _size = size; }
96 unsigned long round_size() const throw()
97 { return l4_round_size(size(), page_shift()); }
98 bool check_limit(l4_addr_t offset) const throw()
99 { return offset < round_size(); }
102 int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
103 int map(l4_addr_t offs, l4_addr_t spot, bool rw,
104 l4_addr_t min, l4_addr_t max, L4::Ipc::Snd_fpage &memory);
105 int stats(L4Re::Dataspace::Stats &stats);
106 //int copy_in(unsigned long dst_offs, Dataspace *src, unsigned long src_offs,
107 // unsigned long size);
108 virtual int phys(l4_addr_t offset, l4_addr_t &phys_addr, l4_size_t &phys_size) throw();
110 int dispatch(unsigned long obj, unsigned long op, L4::Ipc::Iostream &ios);
114 unsigned long _flags;