3 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>,
5 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
6 * economic rights: Technische Universität Dresden (Germany)
8 * This file is part of TUD:OS and distributed under the terms of the
9 * GNU General Public License 2.
10 * Please see the COPYING-GPL-2 file for details.
12 * As a special exception, you may use this file as part of a free software
13 * library without restriction. Specifically, if other files instantiate
14 * templates or use macros or inline functions from this file, or you compile
15 * this file and link it with other files to produce an executable, this
16 * file does not by itself cause the resulting executable to be covered by
17 * the GNU General Public License. This exception does not however
18 * invalidate any other reasons why the executable file might be covered by
19 * the GNU General Public License.
25 #include <l4/sys/types.h>
26 #include <l4/cxx/list>
27 #include <l4/cxx/ipc_server>
28 #include <l4/cxx/ipc_stream>
29 #include <l4/cxx/minmax>
30 #include <l4/re/dataspace>
31 #include <l4/re/dataspace-sys.h>
32 #include <l4/re/protocols>
35 L4::Ipc::Ostream &operator << (L4::Ipc::Ostream &s,
36 L4Re::Dataspace::Stats const &st)
37 { s.put(st); return s; }
39 namespace L4Re { namespace Util {
42 * \brief Dataspace server class.
43 * \ingroup api_l4re_util
45 * The default implementation of the interface provides a continiously
51 typedef L4::Ipc::Gen_fpage<L4::Ipc::Snd_item> Snd_fpage;
54 typedef Snd_fpage::Map_type Map_type;
55 typedef Snd_fpage::Cacheopt Cache_type;
62 Dataspace_svr() throw()
63 : _ds_start(0), _ds_size(0), _map_flags(Snd_fpage::Map),
64 _cache_flags(Snd_fpage::Cached)
67 virtual ~Dataspace_svr() throw() {}
70 * \brief Map a region of the dataspace
72 * \param offset Offset to start within data space
73 * \param local_addr Local address to map to.
74 * \param flags map flags, see #Map_flags.
75 * \param min_addr Defines start of receive window.
76 * \param max_addr Defines end of receive window.
77 * \retval memory Send fpage to map
79 * \return 0 on success, <0 on error
81 int map(l4_addr_t offset, l4_addr_t local_addr, unsigned long flags,
82 l4_addr_t min_addr, l4_addr_t max_addr, L4::Ipc::Snd_fpage &memory);
85 * \brief A hook that is called as the first operation in each map
87 * \param offs Offs param to map
88 * \param flags Flags param to map
89 * \param min Min param to map
90 * \param max Max param to map
91 * \return < 0 on error and the map request will be aborted with that
97 virtual int map_hook(l4_addr_t offs, unsigned long flags,
98 l4_addr_t min, l4_addr_t max)
100 (void)offs; (void)flags; (void)min; (void)max;
105 * \brief Return physical address for a virtual address
107 * \param offset Offset into the dataspace
108 * \retval phys_addr Physical address
109 * \retval phys_size Size of continious physical region
111 * \return Zero on success, else failure
113 virtual int phys(l4_addr_t offset, l4_addr_t &phys_addr, l4_size_t &phys_size) throw();
116 * \brief Take a reference to this dataspace
118 * Default does nothing.
120 virtual void take() throw()
124 * \brief Release a reference to this dataspace
126 * \return Number of references to the dataspace
128 * Default does nothing and returns always zero.
130 virtual unsigned long release() throw()
134 * \brief Copy from src dataspace to this destination dataspace
136 * \param dst_offs Offset into the destination dataspace
137 * \param src_id Local id of the source dataspace
138 * \param src_offs Offset into the source dataspace
139 * \param size Number of bytes to copy
141 * \return Number of bytes copied
143 virtual unsigned long copy(unsigned long dst_offs, l4_umword_t src_id,
144 unsigned long src_offs, unsigned long size) throw()
145 { (void)dst_offs; (void)src_id; (void)src_offs; (void)size; return 0; }
148 * \brief Clear a region in the dataspace
150 * \param offs Start of the region
151 * \param size Size of the region
153 virtual long clear(unsigned long offs, unsigned long size) const throw();
156 * \brief Define the size of the flexpage to map
158 * \return flexpage size
160 virtual unsigned long page_shift() const throw()
161 { return L4_LOG2_PAGESIZE; }
163 virtual bool is_static() const throw()
166 int dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios);
169 unsigned long size() const throw()
171 unsigned long map_flags() const throw()
172 { return _map_flags; }
173 unsigned long rw_flags() const throw()
174 { return _rw_flags; }
175 unsigned long is_writable() const throw()
176 { return _rw_flags & Writable; }
177 unsigned long page_size() const throw()
178 { return 1UL << page_shift(); }
179 unsigned long round_size() const throw()
180 { return l4_round_size(size(), page_shift()); }
181 bool check_limit(l4_addr_t offset) const throw()
182 { return offset < round_size(); }
185 void size(unsigned long size) throw() { _ds_size = size; }
190 Cache_type _cache_flags;